import java.util.Arrays;

public class test {
//    二分查找,必须是有序数组
    public static int binarySesrch(int[] array,int key) {
       int right = array.length-1;
       int left = 0;
       int mid = left + (right-left) / 2;//防止当数值过大时导致溢出
       while(left <= right) {
           if(array[mid] == key){
               return mid;
           }else if(array[mid] > key) {
               right = mid -1;
           }else {
               left = mid + 1;
           }
       }
            return -1;
}

    public static void main(String[] args) {
        int[] array1 = {1,2,3,4};
        int key = 7;
        int src = binarySesrch(array1,key);
//        System.out.println(src);
        System.out.println("hehe");
    }







//    public static int[] transform(int[] src) {
//        int[] array = new int[src.length];
//        for (int i = 0; i < src.length; i++) {
//            array[i] = src[i] * 2;
//        }
//        return array;
//    }
//
//
//    public static void main(String[] args) {
//        int[] ret = {1,2,3,4,5};
//        int[] sum = transform(ret);
//        System.out.println(Arrays.toString(sum));
//    }
}
